<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
			<div class="widget-head">
				<div class="widget-title">新建运费模版</div>
			</div>
			<form id="my-form" class="layui-form" method="post">
				<div class="widget-body layui-col-sm12 layui-col-md12 layui-col-lg12">
						<div class="layui-form-item">
							<label class="layui-form-label">模版名称 </label>
							<div class="layui-col-sm9 layer-midd-left">
								<input type="text" class="layui-input" name="delivery[name]"
									   value="{$model['name']??''}" required>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label form-require">排序 </label>
							<div class="layui-col-sm9 layer-midd-left">
								<input type="number" class="layui-input" name="delivery[sort]"
									   value="{$model['sort']}" required>
								<small>数字越小越靠前</small>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label form-require">计费方式 </label>
							<div class="layui-col-sm9 layer-midd-left">
								<label class="layui-input-inline">
									<input type="radio" name="delivery[method]" value="10" data-am-ucheck {$model['method']['value'] == 10 ? 'checked' : ''}> 按件数

								</label>
								<label class="layui-input-inline">
									<input type="radio" name="delivery[method]" value="20"  data-am-ucheck {$model['method']['value'] == 20 ? 'checked' : ''}>
									按重量
								</label>
							</div>
						</div>
                         
						<div class="layui-form-item">
							<label class="layui-form-label form-require">
								配送区域及运费
							</label>
							<div class="layui-col-md12" >
								<div class=" layer-scrollable-horizontal">   
									<table width="100%" class="layui-table regional-table">
										<thead>
										<tr>
											<th width="42%">可配送区域</th>
											<th>
												<span class="first"> {$model['method'] === 10 ? '首件 (个)' : '首重 (Kg)'}</span>
											</th>
											<th>运费 (元)</th>
											<th>
												<span class="additional"> {$model['method'] === 10 ? '续件 (个)' : '续重 (Kg)'}</span>
											</th>
											<th>续费 (元)</th>
										</tr>
										{notempty name="$model"}
										  {foreach $model['rule'] as $item}
											<tr>
												<td class="am-text-left">
													<p class="selected-content am-margin-bottom-xs">
															{$item['region_content']}
													</p>
													<p class="operation am-margin-bottom-xs">
														<a class="edit" href="javascript:;">编辑</a>
														<a class="delete" href="javascript:;">删除</a>
													</p>
													<input type="hidden" name="delivery[rule][region][]"
														   value="{$item['region']??''}">
												</td>
												<td>
													<input type="number" class="layui-input" name="delivery[rule][first][]"
														   value="{$item['first']??''}" required>
												</td>
												<td>
													<input type="number" name="delivery[rule][first_fee][]" class="layui-input"
														   value="{$item['first_fee']??''}" required>
												</td>
												<td>
													<input type="number" name="delivery[rule][additional][]" class="layui-input"
														   value="{$item['additional']??''}">
												</td>
												<td>
													<input type="number" name="delivery[rule][additional_fee][]" class="layui-input"
														   value="{$item['additional_fee']??''}">
												</td>
											</tr>
									  {/foreach}
									  {/notempty}
										<tr>
											<td colspan="5" class="">
												<a class="add-region layui-btn"
												   href="javascript:;">
													<i class="iconfont icon-dingwei"></i>
													点击添加可配送区域和运费
												</a>
											</td>
										</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div>
							<input type="hidden" name="delivery[delivery_id]" value="{$model['delivery_id']??''}">
						</div>
						<div class="layui-form-item">
								<button type="submit" class="j-submit layui-btn">提交
								</button>
						</div>
				</div>
			</form>
        </div>
    </div>
</div>
<div class="regional-choice"></div>
<script src="assets/user/js/delivery.js"></script>
<script>
    $(function () {

        // 初始化区域选择界面
        var datas = JSON.parse('<?= $regionData ?>');

        // 配送区域表格
        new Delivery({
            table: '.regional-table',
            regional: '.regional-choice',
            datas: datas
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });
</script>
